﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using foodandgo.Helper;
using foodandgo.Models;

namespace foodandgo.Controllers
{
    public class CategoryController : Controller
    {
        //
        // GET: /DanhMuc/

        public ActionResult Index()
        {
            return View();
        }

         public ActionResult List(int catid, int cityid)
         {
             using (var db = new Db())
             {
                var place =
                    db.Places.Join(db.Categories, p => p.CatId, c => c.CatId, (p, c) => new {p, c})
                      .Join(db.Cities, @t => @t.p.CityId, ci => ci.CityId, (@t, ci) => new
                          {
                              @t.p,
                              @t.c,
                              ci
                          }).FirstOrDefault();
                  //if (catname != place.c.CatName.ToSeoUrl())
                return RedirectToActionPermanent("List", new { catid = catid, catname = place.c.CatName.ToSeoUrl(), cityid = cityid, cityname = place.ci.CityName.ToSeoUrl() });
//return View(product);
             }
             // Redirect to proper name
           
        }
    }
}
